package cn.vc.basicmodule.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.ToString;

/**
 * 消息代码
 */
class CODE {
    /**
     * 未登录
     */
    public static int NOT_LOGGED_IN = 1000;
}

public class Result<T> {
    private int code;
    private T data;
    private String msg;

    public Result() {}
    public Result(boolean code) {
        this.code = code?1:0;
    }
    public Result(int code) {
        this.code = code;
    }
    public Result(int code, T data) {
        this.code = code;
        this.data = data;
    }
    public Result(boolean code, T data, String msg) {
        this.code = code?1:0;
        this.data = data;
        this.msg = msg;
    }
    public Result(int code, T data, String msg) {
        this.code = code;
        this.data = data;
        this.msg = msg;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public void setData(T data) {
        this.data = data;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public T getData() {
        return data;
    }

    public String getMsg() {
        return msg;
    }

    @Override
    public String toString() {
        return "Result{" +
                "code=" + code +
                ", data=" + data +
                ", msg='" + msg + '\'' +
                '}';
    }

    /**
     * 未登录
     * @return
     */
    public static<T> Result<T> NOT_LOGGED_IN() {
        return new Result<T>(CODE.NOT_LOGGED_IN, null, "未登录！");
    }
}
